how to read data from txt file in python

36

with open ("data.txt", "r") as myfile:
    data = myfile.read().splitlines()
# where f is the file alias
with open(r"path\to\file.txt", encoding='UTF8') as f:
    contents = f.read()
    print(contents)
with open('the-zen-of-python.txt') as f:
    for line in f:
        print(line)
Code language: JavaScript (javascript)

Comments

Submit
0 Comments